package cn.edu.sgu.www.mhxysy.controller.repository;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.entity.repository.RepositoryGrid;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.repository.RepositoryGridService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "仓库格子管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/repository_grid", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class RepositoryGridController {

    private final RepositoryGridService repositoryGridService;

    @Autowired
    public RepositoryGridController(RepositoryGridService repositoryGridService) {
        this.repositoryGridService = repositoryGridService;
    }

    @ApiOperation("通过仓库ID查询仓库格子列表")
    @RequestMapping(value = "/selectByRepositoryId", method = RequestMethod.GET)
    public JsonResult<List<RepositoryGrid>> selectByRepositoryId(
            @ApiParam(name = "repositoryId", value = "仓库ID", required = true)
            @NotBlank(message = CustomMessages.ROLE_ID_NOT_NULL) String repositoryId) {
        List<RepositoryGrid> list = repositoryGridService.selectByRepositoryId(repositoryId);

        return JsonResult.success(null, list);
    }

}